/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.chinapnr.params;

import org.grayrabbit.pay.CheckUtil;
import org.grayrabbit.pay.chinapnr.Chinapnr;
import org.grayrabbit.pay.chinapnr.common.PnrConstants;
import org.grayrabbit.pay.chinapnr.config.ChinapnrConfigUtil;

/**
 * 退款提交的表单
 * 
 * @author wy
 * @version $Id: ChinapnrForm.java, v 0.1 2012-11-4 下午5:58:20 wy Exp $
 */
public class ChinapnrRefundForm {

    /**交易ID*/
    private String tradeId;

    /**历史交易ID*/
    private String oldTradeId;

    /**退款金额 必须两位小数*/
    private String money;

    /**
     * Getter method for property <tt>tradeId</tt>.
     * 
     * @return property value of tradeId
     */
    public String getTradeId() {
        return tradeId;
    }

    /**
     * Setter method for property <tt>tradeId</tt>.
     * 
     * @param tradeId value to be assigned to property tradeId
     */
    public void setTradeId(String tradeId) {
        this.tradeId = tradeId;
    }

    /**
     * Getter method for property <tt>oldTradeId</tt>.
     * 
     * @return property value of oldTradeId
     */
    public String getOldTradeId() {
        return oldTradeId;
    }

    /**
     * Setter method for property <tt>oldTradeId</tt>.
     * 
     * @param oldTradeId value to be assigned to property oldTradeId
     */
    public void setOldTradeId(String oldTradeId) {
        this.oldTradeId = oldTradeId;
    }

    /**
     * Getter method for property <tt>money</tt>.
     * 
     * @return property value of money
     */
    public String getMoney() {
        return money;
    }

    /**
     * Setter method for property <tt>money</tt>.
     * 
     * @param money value to be assigned to property money
     */
    public void setMoney(String money) {
        this.money = money;
    }

    /**
     * 检查数据
     */
    public void check() {
        CheckUtil.assertIsNumber(tradeId, "tradeId必须为数字");
        CheckUtil.assertRangeLength(tradeId, 6, 16, "tradeId必须为6-16位数字");
        CheckUtil.assertIsNumber(oldTradeId, "oldTradeId必须为数字");
        CheckUtil.assertRangeLength(oldTradeId, 6, 16, "oldTradeId必须为6-16位数字");
        CheckUtil.assertRegex(money, "^\\d{1,9}(\\.\\d{2})$", "必须保留两位小数");
    }

    /**
     * 数据加密
     * 
     * @param baseUrl
     * @return
     */
    public String getChkValue() {
        //Version+CmdId+MerId+OrdId+OldOrdId+RefAmt+DivDetails+BgRetUrl

        String memId = ChinapnrConfigUtil.getChinapnrInfo().getMemId();

        String check = PnrConstants.TRADE_VERSION + PnrConstants.TRADE_TELREFUND + memId + tradeId
                       + oldTradeId + money;

        return Chinapnr.getSignValue(memId, check);
    }

}
